package standard

import "go-forth/pkg/forth"

func readVariable(vm forth.StackVM, name string) forth.Token {
	xt, _, ok := vm.Find(name)
	if !ok {
		panic("missing " + name)
	}
	xt.RunOn(vm) // puts location on stack
	Fetch(vm)
	return vm.Pop()
}

func updateVariable(vm forth.StackVM, name string, value forth.Token) {
	vm.Push(value)
	xt, _, ok := vm.Find(name)
	if !ok {
		panic("missing " + name)
	}
	xt.RunOn(vm) // puts location on stack
	Store(vm)
}
